<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	if(!function_exists('getView')){
		function getView($viewname, $data= null, $t= false){
			$CI = & get_instance();
			$v = $CI->load->view($viewname, $data, $t);
			return $v;
		}
	}
	
	if(!function_exists('is_user_logged_in')){
		function is_user_logged_in(){
			$CI = & get_instance();
			$CI->load->library('session');
			if(!$CI->session->userdata('is_user_logged') || $CI->session->userdata('is_user_logged') == 0)
				return false;
			return true;
		}
	}

	if(!function_exists('serverReferer')){
		function serverReferer(){
			if(isset($_SERVER['HTTP_REFERER'])){
				return true;
			}else{
				return false;
			}
		}
	}

	if(!function_exists('escape')){
		function escape($data){
			$CI = & get_instance();
			$CI->load->database();
			return $CI->db->escape($data);
		}
	}
	if(!function_exists('convertString')){
		function convertString($str) {
		    $str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'a', $str);
		    $str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'e', $str);
		    $str = preg_replace("/(ì|í|ị|ỉ|ĩ|Ì|Í|Ị|Ỉ|Ĩ)/", 'i', $str);
		    $str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'o', $str);
		    $str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'u', $str);
		    $str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ|Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'y', $str);
		    $str = preg_replace("/(đ|Đ)/", 'd', $str);
		    $str = preg_replace("/(B)/", 'b', $str);
		    $str = preg_replace("/(%)/", '', $str);
		    $str = preg_replace("/(')/", '', $str);
		    $str = preg_replace('/(")/', '', $str);
		    $str = preg_replace("/(!|@|#|$|%|^|&|(|)|:|,|;)/", '', $str);
		    $str = preg_replace("/( - )/", '-', $str);
		    $str = preg_replace("/( )/", '-', $str);
		    $str = preg_replace("/(  )/", '-', $str);
		    $str = preg_replace("/(   )/", '-', $str);
		    $str = preg_replace("/(    )/", '-', $str);
		    $str = preg_replace("/(C)/", 'c', $str);
		    $str = preg_replace("/(G)/", 'g', $str);
		    $str = preg_replace("/(L)/", 'l', $str);
		    $str = preg_replace("/(M)/", 'm', $str);
		    $str = preg_replace("/(N)/", 'n', $str);
		    $str = preg_replace("/(H)/", 'h', $str);
		    $str = preg_replace("/(T)/", 't', $str);
		    $str = preg_replace("/(K)/", 'k', $str);
		    $str = preg_replace("/(S)/", 's', $str);
		    $str = preg_replace("/(R)/", 'r', $str);
		    $str = preg_replace("/(V)/", 'v', $str);
		    $str = preg_replace("/(Y)/", 'y', $str);
		    $str = preg_replace("/(W)/", 'w', $str);
		    $str = str_replace('~', '', $str);
		    $str = str_replace('^', '', $str);
		    $str = str_replace('(', '', $str);
		    $str = str_replace(')', '', $str);
		    $str = str_replace('$', '', $str);
		    $str = str_replace('*', '', $str);
		    $str = str_replace('|', '', $str);
		    $str = str_replace('\\', '', $str);
		    $str = str_replace('/', '', $str);
		    $str = str_replace('?', '', $str);
		    $str = str_replace('<', '', $str);
		    $str = str_replace('>', '', $str);   
		    $str = strtolower($str);      
		    return trim($str);
		}
	}

	if(!function_exists('convertDate')){
		function convertDate($format, $date){
			return date($format, strtotime($date));
		}
	}

	if(!function_exists('getCurrentDate')){
		function getCurrentDate(){
			date_default_timezone_set('Asia/Ho_Chi_Minh');
			return date('Y/m/d H:i:s', time());
		}
	}
?>